package com.cloud.alarm.dinger.support;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.cloud.alarm.dinger.core.entity.DingerRequest;

import java.text.MessageFormat;

/**
 * @author: zhou shuai
 * @date: 2024/7/12 22:35
 * @version: v1
 */
public class InteractiveMessage implements CustomMessage {

    @Override
    public String message(DingerRequest request) {
        String applicationName = SpringUtil.getApplicationName();
        String content = request.getContent();
        String title = StrUtil.isNotBlank(request.getTitle()) ? request.getTitle() : "Dinger通知";
        String env = SpringUtil.getActiveProfile();
        return MessageFormat.format(
                "{0}\n- 项目: 【{1}】.\n- 环境: 【{2}】.\n- 内容: {3}.\n- 时间: {4}.",
                title, applicationName, env, content, DateUtil.now());
    }

}
